#!/usr/bin/python -i

from ceorModule import *
import time
import copy

from optparse import OptionParser
parser = OptionParser("usage:  %prog [options] arg1 ")
parser.add_option("-f", "--iniFile", dest="iniFile")


################ MAIN ################
## Is a 2-D box with lenght Lx Ly
if __name__ == "__main__":
  # And God says...
  (options, args) = parser.parse_args()
  if options.iniFile == None: inputfile = "init_conditions/N_000099_Lx_100_Ly_10_t_0000.dat"
  else: inputfile = str(options.iniFile)
  
  #gas = Gas2D(iniFile=inputfile)
  gas = Gas2D(N=49, delta_r=2.0)
  for i in range(gas.N):
    gas.particle[i].vy_new=0.0
  
  gasIni = copy.deepcopy(gas)
  tic = time.time()
  sigma = 1.0
  eps = 0.05
  total_time = 1000000
  ttime = range(total_time)
  dt = 0.001
  timeDim = 1000 
  gasTime = GasTime(gas,timeDim)
  taux = total_time/timeDim

  
  gas.calculateForces_HeatBath(eps, sigma,1,2)
  for i in ttime:
    gas.save_old() # fx_old=fx_new
    gas.stepPosition(dt) # input old variables = > output x_new
    gas.inBox()
    gas.calculateForces_HeatBath(eps, sigma,1,2)
    gas.stepVelocity(dt)
    if i % taux == 0:
      gasTime.saveMicroState(gas,i,dt)
      gasTime.saveState(gas,i,dt)
  gasTime.Etott = gasTime.Ekint+gasTime.Epott
      
  gas.plot()
  toc = time.time()
  print toc-tic

  plt.rc('font', size=25)
  plt.rc('text', usetex=True)
  plt.grid()
  for i in range(gas.N):
    plt.plot(gasTime.time, gasTime.xt[i])
  plt.xlabel("$ t $")
  plt.ylabel("$ x_i $")
  legendas=["$i = "+str(i)+"$"  for i in range(gas.N)]
  plt.legend(legendas, prop={'size':15})
  plt.ylim((gas.particle[0].x_new-1, gas.particle[gas.N-1].x_new+1))
  plt.show()

